from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from django.core import mail


class ContactTest(TestCase):
    def setUp(self):
        #management.call_command('flush', interactive=False, verbosity=1)
        self.client = Client()
            
    def test_index(self):
        response = self.client.post(reverse('contact_us'))
        self.assertContains(response, '', None, status_code=200)
        
    def test_contact_success(self):
        response = self.client.get(reverse('contact_us'))
        self.assertEquals(response.status_code, 200)

        response = self.client.post(reverse('contact_us'), {
           'first_name': 'Joe',
           'surname': 'Bloggs',
           'email': 'test@example.org',
           'query':  'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non feugiat nunc. Nunc mollis nunc vitae odio semper nec porttitor felis convallis.'})
        
        self.assertEquals(len(mail.outbox), 1)
        self.assertEquals(mail.outbox[0].subject, 'StudentHoods: Contact us')
        self.assertEquals(response.status_code, 302)
